package com.ruoyi.web.controller.chargepile;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.chargepile.domain.ChargeConfig;
import com.ruoyi.chargepile.service.ChargeConfigService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 充电配置表 前端控制器
 * </p>
 *
 * @author zxc
 * @since 2024-07-03
 */
@RestController
@RequestMapping("/charge-config")
public class ChargeConfigController {

    @Autowired
    private ChargeConfigService chargeConfigService;


    @GetMapping("/getUserChargeConfig")
    public AjaxResult getUserChargeConfig() {
        Long userId = SecurityUtils.getLoginUser().getUserId();
        LambdaQueryWrapper<ChargeConfig> chargeConfigLambdaQueryWrapper = new LambdaQueryWrapper<>();
        chargeConfigLambdaQueryWrapper
                .eq(ChargeConfig::getUserId, userId);
        ChargeConfig chargeConfig = chargeConfigService.getOne(chargeConfigLambdaQueryWrapper);
        return AjaxResult.success(chargeConfig);
    }

    @PostMapping("/updateUserChargeConfig")
    public AjaxResult updateUserChargeConfig(@RequestBody ChargeConfig chargeConfig) {
        if(chargeConfigService.updateById(chargeConfig)){
            return AjaxResult.success();
        }else{
            return AjaxResult.error();
        }
    }

}

